package cazsy.rj.PrototypePattern;

public class PrototypePattern {
    public static void main(String[] args) throws CloneNotSupportedException {
//        Plane plane1 = new Plane();
//        System.out.println(plane1.getName()+" "+plane1.getType());
//        Plane clone =(Plane) plane1.clone();
//        System.out.println(clone.getName()+" " + clone.getType());

        //创建原始Plane对象
        Plane plane1 = new Plane();
        System.out.println("Original plane:");
        System.out.println("Name: "+plane1.getName()+","+"Type: "+ plane1.getType());
        System.out.println("Passenger: "+plane1.getPassengers());

        //使用深拷贝创建 plane2
        Plane deepClonedPlane = (Plane)plane1.clone();
        System.out.println("\nDeep cloned plane:");
        System.out.println("Name: " + deepClonedPlane.getName() + ", Type: " + deepClonedPlane.getType());
        System.out.println("Passengers: " + deepClonedPlane.getPassengers());

        // 使用浅拷贝创建 plane3
        Plane shallowClonedPlane = plane1.shallowClone();
        System.out.println("\nShallow cloned plane:");
        System.out.println("Name: " + shallowClonedPlane.getName() + ", Type: " + shallowClonedPlane.getType());
        System.out.println("Passengers: " + shallowClonedPlane.getPassengers());

        //修改原始对象plane1的passenger列表
        plane1.getPassengers().add("Passenger 2");

        System.out.println("\nAfter modifying the original plane's passengers:");
        System.out.println("Original passengers: " + plane1.getPassengers());
        System.out.println("Deep cloned passengers: " + deepClonedPlane.getPassengers());
        System.out.println("Shallow cloned passengers: " + shallowClonedPlane.getPassengers());

    }
}
